package com.zw.yzk.kabu.mapper;

import com.zw.yzk.kabu.data.network.entity.CollectedGoodsEntity;
import com.zw.yzk.kabu.model.GoodsModel;
import com.zw.yzk.kabu.utils.CalculateUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhanwei on 2017/3/12.
 */

public class CollectedGoodsMapper {

    @Inject
    public CollectedGoodsMapper() {
    }

    public GoodsModel transfer(CollectedGoodsEntity.Goods goods) {
        GoodsModel model = new GoodsModel();
        model.setId(goods.goodsId);
        model.setBuyable(goods.isBuyable == 1);
        model.setImage(goods.image);
        model.setPrice(CalculateUtils.getRealPrice(goods.originalPrice, goods.discountedPrice));
        model.setShopName(goods.shopName);
        model.setShopId(goods.shopId);
        model.setName(goods.goodsName);

        return model;
    }

    public List<GoodsModel> transfer(CollectedGoodsEntity entity) {
        List<GoodsModel> modelList = new ArrayList<>();
        if(entity.result.goodsList == null || entity.result.goodsList.isEmpty()) {
            return modelList;
        }
        for(CollectedGoodsEntity.Goods goods : entity.result.goodsList) {
            modelList.add(transfer(goods));
        }
        return modelList;
    }
}
